package com.nancy.java_design.builder.demo2;

import java.util.Locale;

/**
 * 构建者模式，拓展
 */
public class Computer {
    private String cpu;
    private String memory;
    private String hardDisk;
    private String mainboard;


    public String getCpu() {
        return cpu;
    }

    public void setCpu(String cpu) {
        this.cpu = cpu;
    }

    public String getMemory() {
        return memory;
    }

    public void setMemory(String memory) {
        this.memory = memory;
    }

    public String getHardDisk() {
        return hardDisk;
    }

    public void setHardDisk(String hardDisk) {
        this.hardDisk = hardDisk;
    }

    public String getMainboard() {
        return mainboard;
    }

    public void setMainboard(String mainboard) {
        this.mainboard = mainboard;
    }

    // 创建一个内部类，该类用于构建Computer
    public static class Builder {
        private String cpu;
        private String memory;
        private String hardDisk;
        private String mainboard;

        public Builder cpu(String cpu) {
            this.cpu = cpu;
            return this;
        }

        public Builder memory(String memory) {
            this.memory = memory;
            return this;
        }

        public Builder hardDisk(String hardDisk) {
            this.hardDisk = hardDisk;
            return this;
        }

        public Builder mainboard(String mainboard) {
            this.mainboard = mainboard;
            return this;
        }

        public Computer build() {
            return new Computer(this);
        }
    }

    private Computer(Builder builder) {
        this.cpu = builder.cpu;
        this.memory = builder.memory;
        this.hardDisk = builder.hardDisk;
        this.mainboard = builder.mainboard;
    }

    @Override
    public String toString() {
        return "Computer{" + "cpu='" + cpu.toUpperCase(Locale.ROOT) + '\'' + ", memory='" + memory.toUpperCase(Locale.ROOT) + '\''
                + ", hardDisk='" + hardDisk.toUpperCase(Locale.ROOT) + '\'' + ", mainboard='" + mainboard.toUpperCase(Locale.ROOT) + '\'' + '}';
    }
}
